<template>
    <header-footer :commonData="{$parent:$parent,indexLogo:1,indexLittleApp:1}">
        <el-container class="fill">
            <el-header style="height: 200px;width: 100%;position: relative;padding: 0 ;">
                <img src="/static/img/indexnew/banner.png" width="100%" height="200px">
                <div class="row noticBox flex_between" @click="toNews(news[0].id)">
                    <div class="noticBoxTitle text_center">{{newsFirdt}}</div>
                    <el-button class="noticLookBtn">最新通告</el-button>
                </div>
            </el-header>


            <el-main class="col flex_center" style="padding: 0;background: #F5F5F5;padding-top: 80px;">
                <div class="indexTitle col text_center" style="margin-bottom: 40px;">
                    <p style="font-size: 40px;font-weight: 500;color: #333333;">继续教育报名</p>
                    <!-- <p style="font-size: 13px;font-weight: 400;
                    color: #333333;">SIGN UP FOR CONTINUING EDUCATION</p> -->
                </div>

                <div class="indexTab row">
                    <div class="indexTabItem col" @click="indexApplyFunc('yjjxjy')">
                        <img src="/static/img/indexnew/tab.png" width="285px" height="10px" class="indexTabImg">
                        <div class="indexTabItemTitle">一级建造师</div>
                        <div class="indexTabItemBtn">立即报名</div>
                    </div>
                    <div class="indexTabItem col" @click="indexApplyFunc('jxej')">
                        <img src="/static/img/indexnew/tab.png" width="285px" height="10px" class="indexTabImg">
                        <div class="indexTabItemTitle">二级建造师</div>
                        <div class="indexTabItemBtn">立即报名</div>
                    </div>
                    <div class="indexTabItem col" @click="indexApplyFunc('jxtzg')">
                        <img src="/static/img/indexnew/tab.png" width="285px" height="10px" class="indexTabImg">
                        <div class="indexTabItemTitle">特种作业人员</div>
                        <div class="indexTabItemBtn">立即报名</div>
                    </div>
                    <div class="indexTabItem col" @click="indexApplyFunc('jxslry')">
                        <img src="/static/img/indexnew/tab.png" width="285px" height="10px" class="indexTabImg">
                        <div class="indexTabItemTitle">三类人员</div>
                        <div class="indexTabItemBtn">立即报名</div>
                    </div>

                    <!-- <div class="indexTabItem col" v-for="(list,index) in getProjects" :key="index"
                        @click="indexApplyFunc(list.projectCode)">
                        <img src="/static/img/indexnew/tab.png" width="285px" height="10px" class="indexTabImg">
                        <div class="indexTabItemTitle">{{list.projectName}}</div>
                        <div class="indexTabItemBtn">立即报名</div>
                    </div> -->
                </div>
                <!-- <div class="onlinestydu col">
                    <div class="col" style="margin-top: 80px;margin-bottom: 62px;">
                        <p style="font-size: 40px;font-weight: 500;color: #FFFFFF;">在线学习</p>
                        <p style="font-size: 13px;font-weight: 400;color: #FFFFFF;">ONLINE LEARNING</p>
                    </div>
                    <div class="onlinestudyBtn flex_center" @click="toStudy">
                        立即学习 <img src="/static/img/indexnew/onlineicon.png" width="46px" height="20px"
                            style="padding-left: 16px;">
                    </div>
                </div> -->
                <div class="noticTongzhi col">
                    <div style="width: 1200px;margin: 0 auto;">
                        <div style="margin-bottom: 40px;">
                            <p style="font-size: 40px;font-weight: 500;color: #333333;">通知公告</p>
                            <!-- <p style="font-size: 13px;font-weight: 400;color: #333333;">NOTICE</p> -->
                        </div>
                        <div class="row flex_between">
                            <div class="noticleft col flex_center" @click="lookMoreNews">
                                <img src="/static/img/indexnew/more.png" width="80px" height="80px">
                                <p style="font-size: 24px;font-weight: 500;color: #FFFFFF;margin-top: 10px;">查看更多</p>
                            </div>
                            <div class="noticright col">
                                <div class="noticItem row" v-for="(item,index) in news" :key="index"
                                    @click="toNews(item.id)">
                                    <div class="noticItemTime">
                                        <span>{{item.createTime.substring(8,10)}}</span>/{{item.createTime.substring(5,7)}}/{{item.createTime.substring(0,4)}}
                                    </div>
                                    <div class="noticItemTitle">{{item.title}}</div>
                                </div>
                            </div>
                            <div style="width: 100px;"></div>
                        </div>
                    </div>
                </div>
            </el-main>
        </el-container>

        <el-dialog class="indexDialog" width="402px" height="467px" :visible.sync="indexDialog">
            <img class="indexTanBg" src="/static/img/index/index_tan.png" width="410px" height="550px" />
            <div class="indexDialogBtnBox">
                <img src="/static/img/apply_success_close.png" width="24px" height="24px" @click="indexDialog=false" />
                <div class="index_tan_p">
                    <button class="indexDialogBtn" @click="faceApply">面授集训</button>
                    <button class="indexDialogBtn" @click="webApply">网教课程</button>
                    <p class="text_center"
                        style="margin-left: 10px;margin-top: 10px;font-size: 18px;line-height: 30px;width: 380px;">
                        注：面授集训报名入口同时含有网教课程的备选
                    </p>
                </div>
            </div>
        </el-dialog>
        <el-dialog title="温馨提示" :show-close="false" center :visible.sync="api.config.isWhether.length>0" width="50%">
            <div style="text-align: center;font-size: 20px;">{{api.config.isWhether}}</div>
        </el-dialog>
        <!--登录后的显示-->
        <div v-if="!String.isEmptyOrNUll($parent.loginInfo.token)" class="row fixedBox">
            <a class="row" @click="toStudy">
                <img src="/static/img/indexnew/lijixuexi.png" width="49px" height="40px">
                <p style="font-size: 34px;font-weight: 600;color: #FFFFFF;margin-left: 16px;">立即学习</p>
            </a>
        </div>
        <!--未登录先去跳转登录-->
        <div v-else class="fixedBox">
            <router-link to="/login" class="row">
                <img src="/static/img/indexnew/lijidenglu.png" width="40px" height="40px">
                <p style="font-size: 34px;font-weight: 600;color: #FFFFFF;margin-left: 16px;">立即登录</p>
            </router-link>
        </div>
        <img src="/static/img/indexnew/lianxius.png" class="fixedTelephone">
    </header-footer>
</template>

<script>
    import headerFooter from '../components/header_and_footer.vue'

var $template = require('easytemplatejs');
    var timer;
    var _this;
    export default {
        name: 'index',
        data() {
            return {
                browser: false,
                showMoviesFeng: true,
                flashShowDialog: false,
                indexDialog: false,
                news: [],
                imgCover: "/static/img/indexMovies.png",
                getProjects: [],
                ulLeft: 0,
                ulWidth: 0,
                num: 0,
                newsFirdt: ""
            }
        },
        beforeCreate: function() {
            _this = this;
        },
        created: function() {
            //获取后台管理点击操作  拿到的user信息  能获取到连接上的user信息
            var user = this.common.getQuery("user");
            console.log("common.getQuery（user）是什么",user)
            if (!String.isEmptyOrNUll(user)) {
                user = JSON.parse(decodeURIComponent(user));
                this.$cookies.set("token", user.token, this.api.config.tokenTime);
                this.$cookies.set("loginInfo", user, this.api.config.tokenTime);
                this.$parent.loginInfo = user;
                this.common.getHttpHeaders().token = user.token;
            }
        },
        mounted: function() {
          //  实验代码
          var url = $template.template("/news/getNewsList/{=newsType}", {newsType:1});
            console.log("实验代码easytemplate",url)

            console.log(this.$sdk)
            this.$sdk.$request.post(this.api.getProjects, {}).then(res=>{
                console.log(res)
                _this.getProjects = res.resultMap;
            }).catch(err=>{
                this.$message.error(err.resultMsg);
            });
            // this.common.post(this.api.getProjects, {}, function(res) {



                
            //     _this.getProjects = res.resultMap;
            // });
            this.getNewsList();

            if (this.common.isMobile()) {
                this.$sdk.toPage("/phone404");
            }
            // this.toStudy();
        },
        methods: {
            toStudy: function() {
                if (this.$parent.loginInfo.userType == 1) {
                    this.common.toPage("/login");
                } else {
                    this.common.toPage("/play/task/0/0");
                }
            },
            getNewsList: function() {
                // this.common.post(this.api.getNewsList, {
                //     newsType: 1
                // }, function(r) {
                //     _this.news = r.resultMap;
                //     _this.newsFirdt = r.resultMap[0].title;
                // });
                
                this.$sdk.$request.post(this.api.getNewsList,{ newsType: 1}).then(data=>{
                    console.log(data);
                    this.news = data.resultMap;
                    this.newsFirdt = data.resultMap[0].title;
                }
                ).catch(err=>{
                    console.log("打印报错",err);
                })
            },
            toNews: function(id) {
                window.open(String.Format('/news/news_info/{0}', id))
            },
            lookMoreNews: function() {
                this.common.toPage("/news/news_center");
            },


            //点击立即报名
            indexApplyFunc: function(str) {
                console.log("先查看是否有token信息",this.$parent.loginInfo.token)
                if(String.isEmptyOrNUll(this.$parent.loginInfo.token)){
                    this.common.toPage("/login")
                    return;
                }
                //this.api.config   就是配置文件里面的自动设置信息
                if (this.api.config.closeMsg.length > 0) {
                    this.$message.error(this.api.config.closeMsg);
                    return;
                }
                //弹框
                if (str == "jxtzg") {
                    this.indexDialog = true;
                    return;
                } else if (str == "jxslry") {
                    if (this.api.config.closeSlryApply == 1) {
                        this.$message.error("三类人员报名通道已关闭！");
                        return;
                    }
                    window.open("/apply/slry_apply/" + str);
                } else if (str == "jxej") {
                    window.open("/apply/online_apply/" + str);
                } else if (str == "yjjxjy") {
                    window.open("/apply/yijian_apply/" + str);
                }

            },
            // 面授集训弹框按钮
            faceApply: function() {
                //this.api.config   就是配置文件里面的自动设置信息
                if (this.api.config.closeFaceApply == 1) {
                    this.$message.error("面授集训通道已关闭！");
                    return;
                }
                this.indexDialog = false;
                // 个人
                if (parseInt(this.$parent.loginInfo.userType) == 0) {
                    window.open("/apply_special/web_education/jxtzg");
                }
            },
            // 在线网校弹框按钮
            webApply: function() {
                this.indexDialog = false;
                if (parseInt(this.$parent.loginInfo.userType) == 0) {
                    window.open("/apply_special/web_education/0");
                }
            }
        },
        components: {
            headerFooter: headerFooter
        }
    }
</script>

<style scoped="scoped">
    .fill {
        width: 100%;
        height: 100%;
        display: flex;
    }

    .col {
        display: flex;
        flex-direction: column;
    }

    .row {
        display: flex;
        flex-direction: row;
    }

    .flex_between {
        display: flex;
        justify-content: space-between;
    }

    .flex_center {
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .noticBox {
        cursor: pointer;
        width: 1200px;
        height: 62px;
        background: #FFFFFF;
        box-shadow: 0px 2px 4px 1px rgba(0, 0, 0, 0.08);
        position: absolute;
        bottom: -32px;
        left: 50%;
        margin-left: -600px;

    }

    .noticBoxTitle {
        flex: 1;
        align-items: center;
        display: flex;
        justify-content: center;
        font-size: 20px;
        font-weight: 400;
        color: #333333;
    }

    .noticLookBtn {
        width: 138px;
        background-color: #3B89CC;
        text-align: center;
        height: 62px;
        font-size: 22px;
        font-weight: 500;
        color: #FFFFFF;
        border: 0;
        outline: none;
        border-radius: 0;
    }

    .indexTabItem {
        width: 285px;
        height: 170px;
        background: #FFFFFF;
        box-shadow: 2px 2px 8px 2px rgba(0, 0, 0, 0.06);
        margin-right: 20px;
    }

    .indexTabItem:last-child {
        margin-right: 0;
    }

    .indexTab {
        width: 1200px;
        margin: 0 auto;
        margin-bottom: 60px;
    }

    .indexTabItem {
        cursor: pointer;
        position: relative;
    }

    .indexTabItemTitle {
        height: 108px;
        line-height: 108px;
        text-align: center;
        font-size: 26px;
        font-weight: 500;
        color: #333333;
    }

    .indexTabItemBtn {
        height: 60px;
        line-height: 60px;
        border-top: 1px solid #CCCCCC;
        text-align: center;
        font-size: 20px;
        font-weight: 400;
        color: #3B89CC;
    }

    .indexTab .indexTabItem:hover .indexTabItemBtn {
        background: #3B89CC !important;
        color: #FFFFFF !important;
        border-top: 1px solid #3B89CC !important;
    }

    .indexTab .indexTabItem:hover .indexTabImg {
        display: block;
    }

    .indexTabImg {
        position: absolute;
        top: 0;
        display: none;
    }

    .onlinestydu {
        width: 100%;
        text-align: center;
        height: 420px;
        background-image: url("/static/img/indexnew/online.png");
    }

    .onlinestudyBtn {
        cursor: pointer;
        font-size: 34px;
        font-weight: 500;
        color: #3B89CC;
        margin: 0 auto;
        width: 1200px;
        height: 104px;
        display: flex;
        align-items: center;
        background: #FFFFFF;
        box-shadow: 2px 2px 10px 2px rgba(255, 255, 255, 0.06);
    }

    .noticTongzhi {
        width: 100%;
        margin: 0 auto;
        background-color: #F5F5F5;
        text-align: center;
        padding-bottom: 132px;
    }

    .noticleft {
        cursor: pointer;
        width: 274px;
        height: 382px;
        background-image: url("/static/img/indexnew/morebg.png");
        /* background: #000000; */
        /* opacity: 0.5; */
        margin-right: 30px;
    }

    .noticright {
        height: 383px;
        overflow: hidden;
        flex: 1;
        border: 1px solid #CCCCCC;
    }

    .noticItem {
        height: 60px;
        line-height: 60px;
        cursor: pointer;
    }

    .noticItemTime {
        font-size: 16px;
        font-family: DINAlternate-Bold, DINAlternate;
        font-weight: bold;
        color: #333333;
        margin-right: 10px;
        padding: 0 10px;
    }

    .noticItemTime span {
        font-size: 34px;
    }

    .noticItemTitle {
        font-size: 20px;
        font-family: PingFangSC-Semibold, PingFang SC;
        font-weight: 600;
        color: #333333;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .noticItem:hover {
        padding: 10px 0;
    }

    .noticItem:hover .noticItemTime {
        background-color: #3B89CC;
        color: #FFFFFF;
    }

    .noticItem:hover .noticItemTitle {
        color: #3B89CC !important;
    }

    .fixedBox {
        text-align: center;
        display: flex;
        justify-content: center;
        align-items: center;
        width: 300px;
        height: 97px;
        background: #3B89CC;
        box-shadow: 2px 2px 7px 0px rgba(0, 0, 0, 0.26);
        border-radius: 6px;
        position: fixed;
        top: 47%;
        right: 20px;
    }

    .fixedBox a {
        width: 100%;
        height: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .fixedTelephone {
        width: 416px;
        height: 122px;
        position: fixed;
        top: 66%;
        right: 0;
    }
</style>
